﻿using Bouyei.GeoCore.Converters;
using Bouyei.GeoCore.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.GeoCore.GeoParsers.EsriJson
{
    public class GeometryWriter
    {
        public GeometryWriter() { }

        public string ToWriter(Geometry geometry)
        {
            if (geometry.GeometryType == GeoType.POINT
                || geometry.GeometryType == GeoType.POINTZ)
            {
                return new EsriJsonPoint(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.LINESTRING
                || geometry.GeometryType == GeoType.LINESTRINGZ
                || geometry.GeometryType == GeoType.MULTILINESTRING
                ||geometry.GeometryType== GeoType.MULTIPOINT)
            {
                return new EsriJsonLineString(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.POLYGON
               || geometry.GeometryType == GeoType.POLYGONZ
               || geometry.GeometryType == GeoType.MULTIPOLYGON)
            {
                return new EsriJsonPolygon(geometry).FromGeometry();
            }
            else
            {
                throw new Exception("not supported:" + geometry.GeometryType);
            }
        }
    }
}
